class TeamFunctionalTests extends functionaltestplugin.FunctionalTestCase {

    final def idNotExist = 100
    final def idExist = 3
    final def idToDelete1 = 17
    final def idToDelete2 = 18

    /*GET*/

    void testXmlRestApiGet200() {
        get("/team/${idExist}.xml")
        assertStatus 200
        assertContentContains """<teamid="3">"""
    }

    void testJsonRestApiGet200() {
        get("/team/${idExist}.json")
        assertStatus 200
        assertContentContains """{"class":"Team","id":"3","""
    }

    void testXmlRestApiGet404() {
        get("/team/${idNotExist}.xml")
        assertStatus 404
        assertContent """<?xmlversion="1.0"encoding="utf-8"?><error><error_code>404</error_code><error_msg>teamnotfoundwithid${idNotExist}</error_msg></error>"""
    }

    void testJsonRestApiGet404() {
        get("/team/${idNotExist}.json")
        assertStatus 404
        assertContent """{"class":"error","error_code":"404","error_msg":"teamnotfoundwithid${idNotExist}"}"""
    }

    /*PUT*/

    /*POST*/
    void testXmlRestApiPost201() {
        post("/team.xml"){
            body{
                """
<team>
    <name>Baca</name>
</team>
"""
            }
        }
        assertStatus 201
        assertContentContains """<team"""
    }

    void testJsonRestApiPost201() {
        post("/team.json"){
            body{
                """
{
    "class":"Team",
    "name":"Baca"
}
"""
            }
        }
        assertStatus 201
        assertContentContains """{"class":"Team","""
    }

    void testXmlRestApiPost500() {
        post("/team.xml"){
            body{
                """
<team>
    <name></name>
</team>
"""
            }
        }
        assertStatus 500
        assertContentContains """<allerrors>"""
    }

    void testJsonRestApiPost500() {
        post("/team.json"){
            body{
                """
{
    "class":"Team",
    "name":""
}
"""
            }
        }
        assertStatus 500
        assertContentContains """{"errors":"""
    }
    /*DELETE*/
    void testXmlRestApiDelete200() {
        delete("/team/${idToDelete1}.xml")
        assertStatus 200
        assertContent """team${idToDelete1}deleted"""
    }

    void testJsonRestApiDelete200() {
        delete("/team/${idToDelete2}.json")
        assertStatus 200
        assertContent """team${idToDelete2}deleted"""
    }

    void testXmlRestApiDelete404() {
        delete("/team/${idNotExist}.xml")
        assertStatus 404
        assertContent """<?xmlversion="1.0"encoding="utf-8"?><error><error_code>404</error_code><error_msg>teamnotfoundwithid${idNotExist}</error_msg></error>"""
    }

    void testJsonRestApiDelete404() {
        delete("/team/${idNotExist}.json")
        assertStatus 404
        assertContent """{"class":"error","error_code":"404","error_msg":"teamnotfoundwithid${idNotExist}"}"""
    }
}
